The Problem:
How can I make it so when a phone number (String) is entered in a form like this:9876543210 it automatically formats it to 987-654-3210
The Script:
1.Please define a function like below in your app:
string Format_Phone(string phone_input)
{ if (((input.phone_input.getAlphaNumeric())).length() != 10) { phone_output = "error"; } else { phone_output = (((( (input.phone_input.getAlphaNumeric()).subString(0,3)) + "-") + (input.phone_input.getAlphaNumeric()).subString(3,6)) + "-") + (input.phone_input.getAlphaNumeric()).subString(6,10); }
return phone_output;
}
2.Invoke the function in your forms On add -->On validate using below code:
2.Invoke the function in your forms On add -->On validate using below code:
if (input.Phone_Format != "")
{
pf = thisapp.Format_Phone(input.Phone_Format);
if ( pf == "error")
{
errorMsg = "Please enter a 10 digit phone number for <b>Primary Phone</b>.";
}
else
{
input.Phone_Format = pf;
}
}